package cn.wolfcode.trip.app.web.controller;

import cn.wolfcode.trip.base.query.HotelQueryObject;
import cn.wolfcode.trip.base.service.IHotelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;

@RestController
@RequestMapping("/hotels")
public class HotelController {
    private final IHotelService hotelService;

    @Autowired
    public HotelController(IHotelService hotelService) {
        this.hotelService = hotelService;
    }

    /*
        查询所有评论
        动作:GET
        资源:/hotels/{type}
        参数:
     */
    @GetMapping()
    public Object getHotels( @ModelAttribute("qo") HotelQueryObject qo) throws Exception {
//        if(qo!=null&& StringUtils.hasLength(qo.getKeyword())) {
//            qo.setKeyword(
//                    URLDecoder.decode(qo.getKeyword(),"UTF-8")
////                    new String(qo.getKeyword().getBytes("ISO8859-1"), StandardCharsets.UTF_8)
//            );
//        }
        return hotelService.queryHotels(qo);
    }

    /*
        查询某个评论
        动作:GET
        资源:/hotels/{id}
        参数:
     */
    @GetMapping("/{id}")
    public Object getHotel(@PathVariable Long id) {
        return hotelService.get(id);
    }
}
